package com.butuh.uang.tuh.ang.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.butuh.uang.tuh.ang.R;
import com.butuh.uang.tuh.ang.util.DecimalFormatUtil;

import cn.droidlover.xdroidmvp.base.XListAdapter;

public class DetailMoneyAdapter extends XListAdapter<Integer> {

    int defaultIndex = 0;

    int  type=0;

    public void setDefaultIndex(int index) {
        defaultIndex = index;
    }


    public DetailMoneyAdapter(Context context,int type) {
        super(context);
        this.type=type;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHloder viewHloder;
        if (convertView == null) {
            viewHloder = new ViewHloder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_detail_money, null);
            viewHloder.mTvMoney = convertView.findViewById(R.id.tv_money);
            convertView.setTag(viewHloder);
        } else {
            viewHloder = (ViewHloder) convertView.getTag();
        }
        if(type==0){
            viewHloder.mTvMoney.setText(DecimalFormatUtil.formatNumberWithMarkSplit(data.get(position),0));
        }else{
            viewHloder.mTvMoney.setText(String.valueOf(data.get(position)));
        }
        if (defaultIndex == position) {
            viewHloder.mTvMoney.setBackgroundResource(R.drawable.shape_detail_button_bg);
            viewHloder.mTvMoney.setTextColor(context.getResources().getColor(R.color.colorAccent));
        } else {
            viewHloder.mTvMoney.setBackgroundColor(Color.TRANSPARENT);
            viewHloder.mTvMoney.setTextColor(context.getResources().getColor(R.color.color_666666));
        }
        return convertView;
    }


    public int getCurrentData() {
        return data.get(defaultIndex);
    }

    class ViewHloder {
        TextView mTvMoney;
    }

}
